﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NMF.Languages.Reflection
{
    public class ReflectiveClass : IClass
    {
        public ReflectiveClass(System.Type mappedType, ReflectiveTypeSystem typeSystem)
        {
            MappedType = mappedType;
            Properties = new PropertyCollection();
            this.typeSystem = typeSystem;
        }

        public PropertyCollection Properties { get; private set; }
        public System.Type MappedType { get; private set; }
        private ReflectiveTypeSystem typeSystem;

        public IProperty GetProperty(string name)
        {
            if (Properties.Contains(name))
            {
                return Properties[name];
            }
            else
            {
                return null;
            }
        }

        public object CreateInstance()
        {
            return Activator.CreateInstance(MappedType);
        }

        public IEnumerable<IProperty> GetProperties()
        {
            return Properties;
        }

        public IEnumerable<IClass> GetBaseTypes()
        {
            throw new NotImplementedException();
        }

        public void AssertIsAssignableFrom(IClass baseClass)
        {
            throw new NotImplementedException();
        }

        public ITypeSystem TypeSystem
        {
            get { return typeSystem; }
        }

        public string Name
        {
            get { return MappedType.Name; }
        }


        public event EventHandler InstanceCreated;


        public void Visit(ITypeVisitor visitor)
        {
            visitor.VisitClass(this);
        }

        public T Visit<T>(ITypeVisitor<T> visitor)
        {
            return visitor.VisitClass(this);
        }

        public T Visit<S, T>(ITypeVisitor<S, T> visitor, S parameter)
        {
            return visitor.VisitClass(this, parameter);
        }
    }
}
